package cn.jb698.codec.msm.generator.v5base.beans;

import java.util.List;
import java.util.Objects;

/**
 * Java文件对象配置
 * @author Administrator
 * @date 2025-03-16 23:04:04
 */
public class BcrudCfgJavaFileObj {

    private int order = 10; // 排序(默认10)
    
    /**
     * 对象名称(Java类名),表类名,类名有冲突时,将该字段初始设置. 例: DtTableName
     */
    private String objName;

    /**
     * 包名称(Java类包名称路径),例: ${basePackage}+".entity"
     */
    private String packageName;

    /**
     * 对象属性名称(Java类属性名(首字母小写)),例: dtTableName
     */
    private String objPropName;

    /**
     * 对象全名(Java类全名),例: com.cpnyxx.entity.model.DtTableName
     */
    private String objFullName;

    /**
     * model类的import列表
     * 例:{ ${entityObj.objFullName} }
     */
    private List<String> importList ;
    
    /**
     * 是否已排序过
     */
    private boolean hasImportListSorted = false;

    /**
     * 
     * @param objName 类名称,
     * @param packageNameExpress java包名称表达式
     */
    public BcrudCfgJavaFileObj(String objName, String packageNameExpress) {
        super();
        if(Objects.isNull(objName) || objName.isEmpty() || Objects.isNull(packageNameExpress) || packageNameExpress.isEmpty() ) {
            throw new IllegalArgumentException("Java对象名称不能为空(obj="+objName+",pkg="+packageNameExpress+")");
        }
        this.objName = objName;
        this.packageName = packageNameExpress;
    }

    public BcrudCfgJavaFileObj() {
        super();
    }

    public int getOrder() {
        return order;
    }

    public void setOrder(int order) {
        this.order = order;
    }

    public String getPackageName() {
        if(Objects.isNull(packageName)) {
            packageName = "${basePackage}" + ".entity";
        }
        return packageName;
    }

    public void setPackageName(String packageName) {
        this.packageName = packageName;
    }

    public String getObjName() {
        return objName;
    }

    public void setObjName(String objName) {
        this.objName = objName;
    }

    public String getObjPropName() {
        if(Objects.isNull(objPropName)) {
            String tmpObjName = this.getObjName();
            objPropName =  tmpObjName.substring(0, 1).toLowerCase() + tmpObjName.substring(1);;
        }
        return objPropName;
    }

    public void setObjPropName(String objPropName) {
        this.objPropName = objPropName;
    }

    public String getObjFullName() {
        if(Objects.isNull(objFullName)) {
            objFullName = this.getPackageName()+"."+this.getObjName();
        }
        return objFullName;
    }

    public void setObjFullName(String objFullName) {
        this.objFullName = objFullName;
    }

    public boolean isHasImportListSorted() {
        return hasImportListSorted;
    }

    public void setHasImportListSorted(boolean hasImportListSorted) {
        this.hasImportListSorted = hasImportListSorted;
    }

    public List<String> getImportList() {
        return importList;
    }

    public void setImportList(List<String> importList) {
        this.importList = importList;
    }

    public void doInitProp() {
        this.setObjFullName(null);
        this.setObjPropName(null);
    };

}
